# H3DU.SurfaceOfRevolution

[Back to documentation index.](index.md)

<a name='H3DU.SurfaceOfRevolution'></a>
### H3DU.SurfaceOfRevolution(curve, minval, maxval, [axis])

A <a href="H3DU.Surface.md">surface evaluator object</a> for a surface of revolution,
which results by revolving
a two-dimensional curve around an axis.

This class is considered a supplementary class to the
Public Domain HTML 3D Library and is not considered part of that
library.

To use this class, you must include the script "extras/evaluators.js"; the
class is not included in the "h3du_min.js" file which makes up
the HTML 3D Library. Example:

    <script type="text/javascript" src="extras/evaluators.js"></script>

#### Parameters

* `curve` (Type: Object)<br>A <a href="H3DU.Curve.md">curve evaluator object</a> that describes a 2-dimensional curve to rotate about the axis of rotation, as specified in the "axis" parameter. The curve's X coordinates correspond to elevation, and its Y coordinates correspond to radius.

 If the curve function draws a curve that goes both above and below the axis of rotation, such as a circle or ellipse, the V coordinates given in _minval_ and _maxval_ must restrict the curve definition to no more than half of the curve.
* `minval` (Type: number)<br>Smallest V coordinate.
* `maxval` (Type: number)<br>Largest V coordinate. If _minval_ is greater than _maxval_, both values will be swapped.
* `axis` (Type: Array.&lt;number>) (optional)<br>Axis of rotation, around which the curve will be rotated to generate the surface of revolution. If null, undefined, or omitted, the positive Z axis (0, 0, 1) will be the axis of rotation. This parameter is a 3-element array describing the X, Y, and Z coordinates, respectively, of a 3D point. The axis of rotation will run in the direction from the origin to the point given in this parameter. This parameter need not be a <a href="tutorial-glmath.md">unit vector</a>.

### Methods

* [endPoints](#H3DU.SurfaceOfRevolution_endPoints)
* [evaluate](#H3DU.SurfaceOfRevolution_evaluate)<br>Finds the coordinates of the given point of this surface.
* [fromFunction](#H3DU.SurfaceOfRevolution.fromFunction)<br>Creates a <a href="H3DU.Surface.md">surface evaluator object</a> for a surface of revolution
whose curve is the graph of a single-variable function.
* [torus](#H3DU.SurfaceOfRevolution.torus)<br>A <a href="H3DU.Surface.md">surface evaluator object</a> for a torus, a special case of a surface of revolution.

<a name='H3DU.SurfaceOfRevolution_endPoints'></a>
### H3DU.SurfaceOfRevolution#endPoints()

<a name='H3DU.SurfaceOfRevolution_evaluate'></a>
### H3DU.SurfaceOfRevolution#evaluate(u, v)

Finds the coordinates of the given point of this surface.

#### Parameters

* `u` (Type: number)<br>U coordinate of the surface to evaluate.
* `v` (Type: number)<br>V coordinate of the surface to evaluate.

#### Return Value

An array containing the coordinates
of the position at the given point. It will have three elements. (Type: Array.&lt;number>)

<a name='H3DU.SurfaceOfRevolution.fromFunction'></a>
### (static) H3DU.SurfaceOfRevolution.fromFunction(func, minval, maxval, [axis])

Creates a <a href="H3DU.Surface.md">surface evaluator object</a> for a surface of revolution
whose curve is the graph of a single-variable function.
The resulting surface will have a circular cross section
along its length.
Examples of surfaces generated by this technique are
cones, frustums, cylinders, spheres, and spheroids (the
bases of these surfaces won't be generated).

#### Parameters

* `func` (Type: function)<br>Function whose graph will be rotated about the axis of rotation, as specified in the "axis" parameter. The function takes a number as a single parameter and returns a number. The return value is effectively the radius of each part of the surface from beginning to end.
* `minval` (Type: number)<br>Smallest parameter of the function. This is a number of units from the origin along the axis of rotation.
* `maxval` (Type: number)<br>Largest parameter of the function. This is a number of units from the origin along the axis of rotation. If _minval_ is greater than _maxval_, both values will be swapped.
* `axis` (Type: Array.&lt;number>) (optional)<br>Axis of rotation, around which the function graph will be rotated to generate the surface of revolution. If null, undefined, or omitted, the positive Z axis (0, 0, 1) will be the axis of rotation. This parameter is a 3-element array describing the X, Y, and Z coordinates, respectively, of a 3D point. The axis of rotation will run in the direction from the origin to the point given in this parameter. This parameter need not be a <a href="tutorial-glmath.md">unit vector</a>.

#### Return Value

Return value. (Type: <a href="H3DU.SurfaceOfRevolution.md">H3DU.SurfaceOfRevolution</a>)

#### Example

The following creates an evaluator for a cone
which starts at the origin and runs 10 units along the Z axis.

    var surf=H3DU.SurfaceOfRevolution.fromFunction(
    function(x) {
    "use strict"; return x/2; }, // use a constantly increasing function
    0, 10);

This is an evaluator for the same cone, but
shifted 3 units back.

    var surf=H3DU.SurfaceOfRevolution.fromFunction(
    function(x) {
    "use strict"; x+=3; return x/2; },
    -3,7);

The following creates an evaluator for a cylinder
which runs from 5 to 10 units, and with a radius of 2 units.

    var surf=H3DU.SurfaceOfRevolution.fromFunction(
    function(x) {
    "use strict"; return 2; }, // use a constant radius
    5, 10);

<a name='H3DU.SurfaceOfRevolution.torus'></a>
### (static) H3DU.SurfaceOfRevolution.torus(outerRadius, innerRadius, [curve], [axis])

A <a href="H3DU.Surface.md">surface evaluator object</a> for a torus, a special case of a surface of revolution.

#### Parameters

* `outerRadius` (Type: number)<br>Radius from the center to the innermost part of the torus.
* `innerRadius` (Type: number)<br>Radius from the inner edge to the innermost part of the torus.
* `curve` (Type: Object) (optional)<br>A <a href="H3DU.Curve.md">curve evaluator object</a> that describes a 2-dimensional curve to serve as the cross section of the torus. The curve need not be closed; in fact, certain special surfaces can result by leaving the ends open. If null, undefined, or omitted, uses a circular cross section with a radius of 1.
* `axis` (Type: Array.&lt;number>) (optional)<br>Axis of rotation, which the torus will pass through. If null, undefined, or omitted, the positive Z axis (0, 0, 1) will be the axis of rotation. This parameter is a 3-element array describing the X, Y, and Z coordinates, respectively, of a 3D point. The axis of rotation will run in the direction from the origin to the point given in this parameter. This parameter need not be a <a href="tutorial-glmath.md">unit vector</a>.

#### Return Value

Return value. (Type: <a href="H3DU.SurfaceOfRevolution.md">H3DU.SurfaceOfRevolution</a>)

[Back to documentation index.](index.md)
